#include<iostream>
#include<cstdio>
#include<set>
#define N 1000000
using namespace std;
const int inf=(int)(1e9);
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int n,q,res,ans;
char c[N+1];
bool used[N+1];
set<string>sw;
bool check(string s)
{
	int res=0;
	for (int i=0;i<s.length();++i)
	{
		if (s[i]=='1') res++;
		else res--;
		if (res<0) return 0;
	}
	res=0;
	for (int i=(int)(s.length())-1;i>=0;--i)
	{
		if (s[i]=='1') res++;
		else res--;
		if (res<0) return 0;
	}
	return 1;
}
void dfs(string s)
{
	if (check(s))
	{
		res=min(res,(int)(s.length()));
		return;
	}
	if (s.length()>15||sw.find(s)!=sw.end()) return;
	sw.insert(s);
	string t,zero;
	for (int i=0;i<=s.length();++i)
	{
		t=zero;
		for (int j=0;j<=i-1;++j) t=t+s[j];
		t=t+'1';
		for (int j=i;j<s.length();++j) t=t+s[j];
		dfs(t);
	}
	return;
}
int main()
{
	freopen("good.in","r",stdin);
	freopen("good.ans","w",stdout);
	int l,r;
	string s,zero;
	n=read(),q=read();
	for (int i=1;i<=n;++i) cin>>c[i];
	while (q--)
	{
		l=read(),r=read(),s=zero,sw.clear(),res=inf;
		for (int i=l;i<=r;++i) s=s+c[i];
		dfs(s),ans^=(res-s.length());
	}
	printf("%d\n",ans);
	return 0;
}
